# include <bits/stdc++.h>
# define N 100005
using namespace std;
int n,m;
vector<pair<int,int>> ans;
void solve(int x1,int y1,int x2,int y2)
{
    if((y2-y1+1)==(x2-x1+1))
    {
        if(x1==x2)
            ans.push_back({x1,y1});
        else
            solve(x1,y1+1,x2,y2);
        return ;
    }
    if(x2-x1+1<y2-y1+1)
    {
        int now=y1;
        while(now==y2 || y2-now+1>x2-x1+1)
        {
            for(int i=x1;i<=x2;i++)
                ans.push_back({i,now});
            now+=x2-x1+1;
        }
        if(now>=y2)
            return ;
        solve(x1,now,x2,y2);
    }
    else
    {
        int now=x1;
        while(now==x2 || x2-now+1>y2-y1+1)
        {
            for(int i=y1;i<=y2;i++)
                ans.push_back({now,i});
            now+=y2-y1+1;
        }
        if(now>=x2)
            return ;
        solve(now,y1,x2,y2);
    }
}
int main()
{
    freopen("bishop.in","r",stdin);
    freopen("bishop.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    solve(1,1,n,m);
    cout<<ans.size()<<'\n';
    for(auto [x,y]:ans)
        cout<<x<<' '<<y<<'\n';
    return 0;
}